package Thread;

public class Demo7 {

    private static boolean isQuit = false;

    public static void main(String[] args) throws InterruptedException {
        Thread th = new Thread(() -> {
            while(!isQuit){
                System.out.println("hello thread");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
            System.out.println("线程执行结束");
        });

        th.start();

        Thread.sleep(3000);

        //修改变量 isQuit ，就能影响到 t 线程的结束
        System.out.println(" main 线程尝试终止 t 线程");
        isQuit = true;
    }
}
